package com.ilop.sthome.ui.activity.scene;

import android.content.Intent;
import android.text.TextUtils;

import com.example.common.base.BaseBindActivity;
import com.ilop.sthome.common.CommonId;
import com.ilop.sthome.data.enums.SmartDevice;
import com.ilop.sthome.data.greenDao.DeviceInfoBean;
import com.siterwell.familywellplus.R;
import com.siterwell.familywellplus.databinding.ActivityChooseHumitureBinding;

/**
 * @author skygge
 * @date 2020/7/10.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：选择温湿度探测器触发条件
 */
public class ChooseHumitureActivity extends BaseBindActivity<ActivityChooseHumitureBinding> {

    private boolean isAdd;
    private DeviceInfoBean mDevice;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_choose_humiture;
    }

    @Override
    protected void initialize() {
        super.initialize();
        mDevice = (DeviceInfoBean) getIntent().getSerializableExtra(CommonId.KEY_DEVICE);
        isAdd = getIntent().getBooleanExtra(CommonId.KEY_ADD_NEW, false);
    }

    @Override
    protected void initData() {
        super.initData();
        if (TextUtils.isEmpty(mDevice.getSubdeviceName())){
            String title = getString(SmartDevice.getType(mDevice.getDevice_type()).getTypeStrId()) + mDevice.getDevice_ID();
            mDBind.tvHumitureTitle.setText(title);
        }else {
            mDBind.tvHumitureTitle.setText(mDevice.getSubdeviceName());
        }
    }

    @Override
    protected void initListener() {
        super.initListener();
        mDBind.ivBack.setOnClickListener(v -> finish());
        mDBind.tempLower.setOnClickListener(v -> gotoSetHumiture(0));
        mDBind.tempHigher.setOnClickListener(v -> gotoSetHumiture(1));
        mDBind.humLower.setOnClickListener(v -> gotoSetHumiture(2));
        mDBind.humHigher.setOnClickListener(v -> gotoSetHumiture(3));
    }

    private void gotoSetHumiture(int type){
        Intent intent = new Intent();
        intent.setClass(mContext, SettingHumitureActivity.class);
        intent.putExtra(CommonId.KEY_ADD_NEW, isAdd);
        intent.putExtra(CommonId.KEY_DEVICE, mDevice);
        intent.putExtra(CommonId.KEY_MESSAGE_TYPE, type);
        startActivity(intent);
        finish();
    }
}
